
import java.text.DecimalFormat;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author 490501
 */
public class MainApplet extends java.applet.Applet {
    private DecimalFormat df; //skrive ut tallene med to desimaler
    private double area; //area of simulation unit (gulvareal)
    private double high; //høyde av tak
    private double volume; // vollum av hus
    private double windowsArea;// felles vinduareal i hus
    private double wallArea; //areal av alle vegger + gulv + tak 
    private double utak, uGulv, uVegger, uVinduer; //u verdier til forskjellige elementer 
    private double tempInside, tempOutside; //innetemperatur og temperatur ute
    private double averageTemp; //ars gjennomsnittlig temperatur i C
    double ventilationLoss; //ventilasjonsvarmetap
    double t; // tid i sekunder
    


    /**
     * Initializes the applet MainApplet
     */
    public void init() {
        df = new DecimalFormat("#.#");
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {

                public void run() {
                    initComponents();
                    beregnForbruk();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    /**
     * 
     */
    public void beregnForbruk() {
        //beregner vollum av enhet
        this.volume = this.area * this.high;
        //plukker ut vinduareal
        //antar at enhet har kvadratform for å beregne perimeter
        //antar at enebolig har 4 yttrevegg + tak + gulv
        //antar at rekkehus har 2 yttrevegg + tak + gulv
        //antar at leilighet har 1 yttervegg og varm tak og gulv
        double r = Math.sqrt(this.area/2);
        double perimeter = 4*Math.sqrt(2*r);
        this.wallArea = perimeter * this.high - this.windowsArea;
        double difference = this.tempInside - this.averageTemp;
        double lossHeat = 0.00;
        switch(this.boxBuildingType.getSelectedIndex()) {
            case 0://enebolig
                lossHeat = ((difference * area * this.uGulv) + (difference * area * this.utak) + (difference * this.wallArea * this.uVegger) + (difference * this.windowsArea * this.uVinduer));
                break;
            case 1://rekkehus
                lossHeat = ((difference * area * this.uGulv) + (difference * area * this.utak) + (difference * (this.wallArea/2) * this.uVegger) + (difference * this.windowsArea * this.uVinduer));
                break;
            case 2://leilighet
                lossHeat = ( (difference * (this.wallArea/4) * this.uVegger) + (difference * this.windowsArea * this.uVinduer));
                break;
        }
            
        
        //ventilasjonstap = (tetthet(kg/m^3) * vollum(m^3))/(29 g/moll)*((T1-T2)*7/2*R(gasskonstant))/t(tid i sekunder)
        //antar at ved naturlig ventilasjon luft byttes hver 2,5 timer
        //antar at ved avtrekk luft byttes hver 1 time
        //antar lufttetthet = sørNorge = 1,2466; midt-Norge = 1,2690; Nordland, Troms og Finmark = 1,2920
        double mm = 0.029;//molarmass kg/moll
        double R = 8.3144621;//gasskonstant G/moll
        double tetthet = 1.2754;
        if(this.boxBuildingsArea.getSelectedIndex() == 0) {tetthet = 1.2466;}
        else if(this.boxBuildingsArea.getSelectedIndex() == 1){tetthet = 1.2690;}
        else if(this.boxBuildingsArea.getSelectedIndex() == (2 | 3)){tetthet = 1.2920;}
        ventilationLoss = (tetthet*this.volume)/mm*((this.sliderTemperatureInside.getValue() - this.averageTemp)*7/2*R)/t;
        //viser resultater
        this.labelvarmeTap.setText("<html>Transmisjonsvarmetap: "+df.format(lossHeat/1000)+ " kW/T</html>");
        this.labelVolume.setText("<html>Vollum: "+df.format(this.volume)+ " m<sup>3</sup></html>");
        this.labelVentLoss.setText("<html>Ventilasjonstap: "+df.format(this.ventilationLoss/1000)+ " kW/T</html>");
    }

    /**
     * This method is called from within the init() method to initialize the
     * form. WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPaneMain = new javax.swing.JTabbedPane();
        jPaneHome = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        boxBuildingYear = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        boxBuildingsArea = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        boxBuildingType = new javax.swing.JComboBox();
        sliderFloorArea = new javax.swing.JSlider();
        jLabel4 = new javax.swing.JLabel();
        labelFloorArea = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        sliderHoyede = new javax.swing.JSlider();
        labelHoyede = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        sliderWindowsArea = new javax.swing.JSlider();
        labelWindowsArea = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        sliderTemperatureInside = new javax.swing.JSlider();
        labelTemp = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jSlider1 = new javax.swing.JSlider();
        jSlider2 = new javax.swing.JSlider();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        boxVentilation = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        labelVolume = new javax.swing.JLabel();
        labelvarmeTap = new javax.swing.JLabel();
        labelVentLoss = new javax.swing.JLabel();

        setStub(null);

        jPaneMain.setMaximumSize(new java.awt.Dimension(1280, 1024));
        jPaneMain.setMinimumSize(new java.awt.Dimension(800, 600));
        jPaneMain.setPreferredSize(new java.awt.Dimension(800, 600));

        jPaneHome.setPreferredSize(new java.awt.Dimension(800, 600));

        jLabel1.setText("Byggeår");

        boxBuildingYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "før 1987", "1987-1997", "etter 1997" }));
        boxBuildingYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxBuildingYearActionPerformed(evt);
            }
        });

        jLabel2.setText("Byggeområde");

        boxBuildingsArea.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sør-Norge", "Midt-Norge", "Nordland og Troms", "Finmark" }));
        boxBuildingsArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxBuildingsAreaActionPerformed(evt);
            }
        });

        jLabel3.setText("Byggningstype");

        boxBuildingType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enebolig", "Rekkehus", "Leilighet" }));
        boxBuildingType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxBuildingTypeActionPerformed(evt);
            }
        });

        sliderFloorArea.setMaximum(300);
        sliderFloorArea.setValue(0);
        sliderFloorArea.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderFloorAreaStateChanged(evt);
            }
        });

        jLabel4.setText("Gulvarea i kvadrattmeter");

        labelFloorArea.setText("0");

        jLabel5.setText("Høyde i meter");

        sliderHoyede.setMaximum(500);
        sliderHoyede.setMinimum(200);
        sliderHoyede.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderHoyedeStateChanged(evt);
            }
        });

        labelHoyede.setText("2");

        jLabel6.setText("Vinduareal (felles)");

        sliderWindowsArea.setMaximum(1000000);
        sliderWindowsArea.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderWindowsAreaStateChanged(evt);
            }
        });

        labelWindowsArea.setText("0");

        jLabel7.setText("Inneklima");

        sliderTemperatureInside.setMaximum(40);
        sliderTemperatureInside.setMinimum(10);
        sliderTemperatureInside.setValue(20);
        sliderTemperatureInside.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderTemperatureInsideStateChanged(evt);
            }
        });

        labelTemp.setText("20 ");

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, java.awt.Color.lightGray, null, null));

        jLabel8.setText("Temperatursenking");

        jSlider1.setMaximum(40);
        jSlider1.setMinimum(10);

        jSlider2.setMaximum(24);
        jSlider2.setValue(0);

        jLabel9.setText("grader");

        jLabel10.setText("timer ");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)))
                .addContainerGap(94, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel11.setText("Ventilasjon");

        boxVentilation.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Naturlig", "Avtrekk" }));
        boxVentilation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxVentilationActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPaneHomeLayout = new javax.swing.GroupLayout(jPaneHome);
        jPaneHome.setLayout(jPaneHomeLayout);
        jPaneHomeLayout.setHorizontalGroup(
            jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPaneHomeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addComponent(boxBuildingYear, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addComponent(boxBuildingsArea, 0, 120, Short.MAX_VALUE)
                    .addComponent(boxBuildingType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel11)
                    .addComponent(boxVentilation, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPaneHomeLayout.createSequentialGroup()
                        .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sliderTemperatureInside, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelTemp, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPaneHomeLayout.createSequentialGroup()
                        .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sliderWindowsArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelWindowsArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPaneHomeLayout.createSequentialGroup()
                        .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sliderFloorArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(sliderHoyede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelHoyede, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                            .addComponent(labelFloorArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPaneHomeLayout.setVerticalGroup(
            jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPaneHomeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPaneHomeLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPaneHomeLayout.createSequentialGroup()
                                .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(sliderFloorArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelFloorArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6))
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sliderWindowsArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(jPaneHomeLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPaneHomeLayout.createSequentialGroup()
                                .addComponent(boxBuildingYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(boxBuildingsArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(boxBuildingType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPaneHomeLayout.createSequentialGroup()
                                .addGap(50, 50, 50)
                                .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(sliderHoyede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(labelHoyede, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(labelWindowsArea, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6)))
                        .addGap(12, 12, 12)))
                .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPaneHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPaneHomeLayout.createSequentialGroup()
                            .addComponent(jLabel7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(sliderTemperatureInside, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(labelTemp, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPaneHomeLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boxVentilation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(291, Short.MAX_VALUE))
        );

        jPaneMain.addTab("Oppvarming", jPaneHome);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 795, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 520, Short.MAX_VALUE)
        );

        jPaneMain.addTab("Belysning", jPanel2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 795, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 520, Short.MAX_VALUE)
        );

        jPaneMain.addTab("Utstyr", jPanel3);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 795, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 520, Short.MAX_VALUE)
        );

        jPaneMain.addTab("Vann", jPanel5);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        labelVolume.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelVolume.setText("Vollum: ");

        labelvarmeTap.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelvarmeTap.setText("Transmisjonsvarmetap:");

        labelVentLoss.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelVentLoss.setText("Ventilasjonstap:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(labelvarmeTap, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                    .addComponent(labelVentLoss, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(labelVolume, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelVolume, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelvarmeTap, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelVentLoss, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPaneMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPaneMain, javax.swing.GroupLayout.PREFERRED_SIZE, 545, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void sliderWindowsAreaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderWindowsAreaStateChanged
        this.labelWindowsArea.setText("<html>"+df.format((double) (this.sliderWindowsArea.getValue() / 10000.00)) + " m<sup>2</sup></html>");
        this.windowsArea = (double) (this.sliderWindowsArea.getValue() / 10000.00);
        beregnForbruk();
    }//GEN-LAST:event_sliderWindowsAreaStateChanged

    private void sliderHoyedeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderHoyedeStateChanged
        this.labelHoyede.setText(String.valueOf((double) (this.sliderHoyede.getValue() / 100.00)) + " m");
        this.high = (double) (this.sliderHoyede.getValue() / 100.00);
        beregnForbruk();
    }//GEN-LAST:event_sliderHoyedeStateChanged

    private void sliderFloorAreaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderFloorAreaStateChanged
        this.labelFloorArea.setText("<html>"+String.valueOf(this.sliderFloorArea.getValue()) +" m<sup>2</sup></html>");
        this.area = this.sliderFloorArea.getValue();
        beregnForbruk();
    }//GEN-LAST:event_sliderFloorAreaStateChanged

    private void boxBuildingTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxBuildingTypeActionPerformed
        //Vi antar her at enebolig har 4 yttrevegg, rekkehus har 2 yttrevegg, og leilghet hsr kun en yttervegg+ har varm tak og gulv slik at vi 
        //slipper det ved beregning
        beregnForbruk();
    }//GEN-LAST:event_boxBuildingTypeActionPerformed

    private void boxBuildingsAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxBuildingsAreaActionPerformed
        /**
         * Må ha tallene , nå dtår tallene fra tak
         */
        int i = this.boxBuildingsArea.getSelectedIndex();
        switch(i) {
            case 0: //sørNorge
                this.averageTemp = 6;
                break;
            case 1: //midtNorge
                this.averageTemp = 3;
                break;
            case 2: //Nordland og Troms
                this.averageTemp = 1.1;
                break;
            case 3: //Finmark
                this.averageTemp = 0.5;
                break;
                
        }
        beregnForbruk();
    }//GEN-LAST:event_boxBuildingsAreaActionPerformed

    private void boxBuildingYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxBuildingYearActionPerformed
        /**
         * Byggear: 1 - før 1987 2 - 1987-1997 3 - etter 1997 //videre skal implementeres frem til NS 3700
         * 
         *  U-verier:
         *      før 1987; tak 0,23; gulv 0,3; yttrevegger 0,45 (inkludert vindutap)
         *      1987-1997; tak 0,20; gulv 0,3; yttrevegger 0,3; vinduer 2,4
         *      fra 1997; tak 0,15; gulv 0,15; yttrevegger 0,22 vinduer 1,6
         *      fra 1. juli 2007; tak 0,13; gulv 0,15; yttrevegger 0,18; vinduer 1,2
         *      fra 2010(NS 3700)tak 0,13; gulv 0,15; yttrevegger 0,15; vinduer 0,8
         */
        int year = this.boxBuildingYear.getSelectedIndex() + 1;
        switch(year) {
            case 1:
                utak = 0.23;
                uGulv = 0.3;
                uVegger = 0.45;
                break;
            case 2:
                utak = 0.20;
                uGulv = 0.3;
                uVegger = 0.3;
                uVinduer = 2.4;
                break;
            case 3:
                utak = 0.15;
                uGulv = 0.15;
                uVegger = 0.22;
                uVinduer = 1.6;
                break;
            default:
                break;
                    
        }

        beregnForbruk();
    }//GEN-LAST:event_boxBuildingYearActionPerformed

    private void sliderTemperatureInsideStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderTemperatureInsideStateChanged
        this.labelTemp.setText(String.valueOf("<html>"+this.sliderTemperatureInside.getValue()+" C<sup>o</sup></html>"));
        this.tempInside = this.sliderTemperatureInside.getValue();
        beregnForbruk();
    }//GEN-LAST:event_sliderTemperatureInsideStateChanged

    private void boxVentilationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxVentilationActionPerformed
        t = (this.boxVentilation.getSelectedIndex() == 1) ? 3600 : 3600*2.5;       
        beregnForbruk();
        

    }//GEN-LAST:event_boxVentilationActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxBuildingType;
    private javax.swing.JComboBox boxBuildingYear;
    private javax.swing.JComboBox boxBuildingsArea;
    private javax.swing.JComboBox boxVentilation;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPaneHome;
    private javax.swing.JTabbedPane jPaneMain;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JSlider jSlider2;
    private javax.swing.JLabel labelFloorArea;
    private javax.swing.JLabel labelHoyede;
    private javax.swing.JLabel labelTemp;
    private javax.swing.JLabel labelVentLoss;
    private javax.swing.JLabel labelVolume;
    private javax.swing.JLabel labelWindowsArea;
    private javax.swing.JLabel labelvarmeTap;
    private javax.swing.JSlider sliderFloorArea;
    private javax.swing.JSlider sliderHoyede;
    private javax.swing.JSlider sliderTemperatureInside;
    private javax.swing.JSlider sliderWindowsArea;
    // End of variables declaration//GEN-END:variables
}
